unit fileutils;

interface

uses classes, sysutils;

function readfile(filename: string): string;
procedure writefile(filename: string; s: string);

implementation

function readfile(filename: string): string;
var
  Stream: TStream;
  Size: Integer;
begin
  Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
  try
    Size := Stream.Size - Stream.Position;
    SetString(Result, nil, Size);
    Stream.Read(Pointer(Result)^, Size);
  finally
    Stream.Free;
  end;
end;

procedure writefile(filename: string; s: string);
var
  Stream: TStream;
begin
  Stream := TFileStream.Create(FileName, fmCreate);
  try
    Stream.WriteBuffer(Pointer(S)^, Length(S));
  finally
    Stream.Free;
  end;
end;

end.
 